$(function () {
	//修改组团
	$("#btn_buildingUpdate").on("click", function(){
		var buildingId = $("input[name='buildingId']").val();
		var parentName = $("input[name='parentName']").val();
		buildingUpdate(buildingId, parentName);
	});
	
	//批量修改,修改内容为房源
	$("#btn_buildingBatchUpdate").on("click", function(){
		var projectId=$("#projectId").val();
		var buildingId = $("input[name='buildingId']").val();
		var url=jypath+"/estate/projectRoom/toBatchUpdate?projectId="+projectId+"&buildingId="+buildingId;
		window.location.href=url;
	});
	
	//删除组团
	$("#btn_buildingDel").on("click", function(){
		var buildingId = $("input[name='buildingId']").val();
		del(buildingId);
	});
	
	
});

//楼栋修改弹出层
function buildingUpdate(buildingId, parentName){
	JY.Ajax.doRequest(null,jypath+'/estate/projectBuilding/viewLC',{id:buildingId},function(data){
		setBuildingFormLC(data);
		$("#buildingFormLC label[name='parentName']").text(parentName);
    	save("修改楼栋","/estate/projectBuilding/editLC", buildingId);
	});
}
function save(title, url, id){
	JY.Model.editBig("buildingDivLC",title,function(){
		if(JY.Validate.form("buildingFormLC")){
			var that =$(this);
			JY.Ajax.doRequest("buildingFormLC",jypath +url,null,function(data){	
				that.dialog("close");
	        	JY.Model.info(data.resMsg,function(){
	        		var url = jypath + "/estate/projectBuilding/detail?id="+id;
	        		$.post(url, null, function(data){
	        			$("#rightContentDiv").html(data);
	        		});
        		});    
			 });
		}	
	});
}

function del(id){
	JY.Model.confirm("该操作将同步删除其下所有子孙节点的信息!&emsp;是否确认删除？",function(){	
		JY.Ajax.doRequest(null,jypath+'/estate/projectBuilding/delete',{id:id},function(data){
			JY.Model.info(data.resMsg,function(){
				$("#rightContentDiv").html("");
 				if(data.res == 1){
 	 				deleteNode();
 	 			}
			});
		});
	});
}

function setBuildingFormLC(data){
	var obj = data.obj;
	$("#buildingFormLC input[name$='id']").val(JY.Object.notEmpty(obj.id));
	$("#buildingFormLC input[name$='buildingName']").val(JY.Object.notEmpty(obj.buildingName));
	$("#buildingFormLC input[name$='buildingCode']").val(JY.Object.notEmpty(obj.buildingCode));
	$("#buildingFormLC select[name$='deliveryFlag']").val(JY.Object.notEmpty(obj.deliveryFlag));
	$("#buildingFormLC input[name$='deliveryDateOrigin']").val(JY.Object.notEmpty(JY.Date.Format(obj.deliveryDate,"yyyy-MM-dd")));
	$("#buildingFormLC input[name$='openTimeOrigin']").val(JY.Object.notEmpty(JY.Date.Format(obj.openTime,"yyyy-MM-dd")));
	$("#buildingFormLC input[name$='defaultEarnest']").val(JY.Object.notEmpty(obj.defaultEarnest));
	$("#buildingFormLC input[name$='salesPermissionNo']").val(JY.Object.notEmpty(obj.salesPermissionNo));
	$("#buildingFormLC input[name$='salesPermissionDateOrigin']").val(JY.Object.notEmpty(JY.Date.Format(obj.salesPermissionDate,"yyyy-MM-dd")));
	$("#buildingFormLC textarea[name$='remark']").val(JY.Object.notEmpty(obj.remark));
	$("#buildingFormLC select[name$='renovationType']").val(JY.Object.notEmpty(obj.renovationType));
	$("#buildingFormLC input[name$='renovationDesc']").val(JY.Object.notEmpty(obj.renovationDesc));

}



